//
// Created by zlf on 20-1-12.
//

#ifndef ME_NOTE3_NOTE_HXX
#define ME_NOTE3_NOTE_HXX

#include <QtCore/QString>
#include <QtCore/QDateTime>
#include <QtCore/QDebug>

#include <vector>

#include <odb/core.hxx>
#include <odb/qt/lazy-ptr.hxx>
#include <odb/tr1/memory.hxx>

#include <odb/tr1/lazy-ptr.hxx>

using odb::tr1::lazy_weak_ptr;
using odb::tr1::lazy_shared_ptr;
using std::vector;

class NoteTree;

#pragma db object table("note")

class Note {
public:
    typedef ::NoteTree NoteTree_Type;

    Note(QString name, lazy_shared_ptr<NoteTree_Type> notetree)
            : name_(name), notetree_(notetree) {
        type_ = 1;
        content_type_ = 1;
        html_ = "";
        text_ = "";
        create_dt_ = QDateTime::currentDateTime();
        update_dt_ = QDateTime::currentDateTime();
    }

    const lazy_shared_ptr<NoteTree_Type> &notetree() const {
        return notetree_;
    }

    void notetree(lazy_shared_ptr<NoteTree_Type> notetree) {
        notetree_ = notetree;
    }

    const QString &name() const {
        return name_;
    }

    void setName(QString name) { name_ = name; }

    int type() { return type_; }

    int content_type() { return content_type_; }

    const QString &text() { return text_; }

    void setText(QString text) {
        text_ = text;
//        extras_.change();
    }

    const QString &html() { return html_; }

    void setHtml(QString html) {
        html_ = html;
//        extras_.change();
    }

    const QDateTime &create_dt() { return create_dt_; }

    const QDateTime &update_dt() { return update_dt_; }


    // The extras section accessor and modifier. Notice that they are
    // by-reference.
    //附加部分访问器和修改器。 注意，它们是引用。
//    const odb::section& extras_section() const {
//        return extras_;
//    }
//    odb::section& extras_section() {
//        return extras_;
//    }
private:
    friend class odb::access;

    Note() {}

#pragma db id auto type("INTEGER")
    int id_;


//雇员的雇佣者
#pragma db not_null type("INTEGER")
    lazy_shared_ptr<NoteTree_Type> notetree_;

#pragma db not_null type("VARCHAR(30)") column("name")
    QString name_;
    int type_;
    int content_type_;

//#pragma db section(extras_)
    QString html_;
//#pragma db section(extras_)
    QString text_;

#pragma db not_null readonly options("DEFAULT CURRENT_TIMESTAMP")//readonly更新数据库时，对只读数据成员的更改将被忽略
    QDateTime create_dt_;
#pragma db not_null options("DEFAULT CURRENT_TIMESTAMP")
    QDateTime update_dt_;

//#pragma db load(lazy) update(change)
//    odb::section extras_;
};

#endif //ME_NOTE3_NOTE_HXX
